package top.starshine.pack;

public interface JsonSerializable extends java.io.Serializable {

    /**
     * <h2 color="#409EFF"> !!! 有编译之后实现方法，这里是空 !!! </h2>
     *
     * @Since: 🫵👁️👁️👉 [ @git/develop ][ @date/2025-03-22 ][ @author/??? ]
     */
    default StringBuilder genJsonBody () {
        throw new UnsupportedOperationException("not implemented genJsonBody method");
    }

    /**
     * <h2 color="#409EFF"> 调用前处理 </h2>
     *
     * @Since: 🫵👁️👁️👉 [ @git/master ][ @date/2025-04-27 ][ @author/??? ]
     */
    default StringBuilder genJsonBodyBefore () {
        //return top.starshine.pack.JsonSerializableSupport.getCacheStringBuilder().append('{');
        return JsonSerializableSupport.systemStringBuilderPool.borrow().append('{');// 取出
    }

    /**
     * <h2 color="#409EFF"> 转为 string </h2>
     *
     * @Since: 🫵👁️👁️👉 [ @git/master ][ @date/2025-04-27 ][ @author/??? ]
     */
    default String toJson () {
        StringBuilder sb = this.genJsonBody();
        try {
            return sb.append('}').toString();
        } finally {
            JsonSerializableSupport.systemStringBuilderPool.retrieve(sb);// 回收
        }
    }

}
